<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
require ("../includes/DB_sql.php");
/*function addBlogInfo($arr)
{
	$sql = "INSERT INTO `blog_info` (`BID` , `Blog_Title` , `Blog_Descripton` , `Blog_LastBuildDate`) VALUES (NULL ," . $arr[title] . "," . $arr[link] . "," . $arr[Descripton] . "," . $arr[LastBuildDate] . ")";
	wt_cmsDb::wt_query($sql);
}*/
function printl($str) //自定义打印换行
{
	echo ($str);
	echo ("\n");
}
class AminoAcid
{
    //var $name;  // aa 姓名
    //var $symbol;    // 三字母符号
    //var $code;  // 单字母代码
    //var $type;  // hydrophobic, charged 或 neutral
	var $title;  //博文标题
	var $link;  //博文链接
	var $comments; //回复内容
	var $pubDate; //发表日期
	var $dc_creator; //作者名字
	var $content_encoded; //文章内容

    function AminoAcid ($aa)
    {
        foreach ($aa as $k=>$v)
		{
			$this->$k = $aa[$k];
		}
    }
}
function readDatabase($filename)
{
    // 读取 aminoacids 的 XML 数据
    $data = implode("",file($filename));
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $values, $tags);
    xml_parser_free($parser);

    // 遍历 XML 结构
	//print_r ($tags);
    foreach ($tags as $key=>$val) {
        if ($key == "item") {
            $molranges = $val;
			//echo count($molranges);//单元数目
            // each contiguous pair of array entries are the
            // lower and upper range for each molecule definition
            for ($i=0; $i < count($molranges); $i+=2) {
                $offset = $molranges[$i] + 1;
                $len = $molranges[$i + 1] - $offset;
                $tdb[] = parseMol(array_slice($values, $offset, $len));
            }
        }
		else {
            continue;
        }
    }
    return $tdb;
}

function parseMol($mvalues)
{
    for ($i=0; $i < count($mvalues); $i++) {
		switch($mvalues[$i]["tag"])
		{
			case "dc:creator" : $mvalues[$i]["tag"] = "dc_creator";break;
			case "content:encoded" : $mvalues[$i]["tag"] = "content_encoded";break;
			case "slash:comments" : $mvalues[$i]["tag"] = "slash_comments";break;
			case "wfw:commentRss" : $mvalues[$i]["tag"] = "wfw_commentRss";break;
		}
        $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
    }
    return $mol;
}

//readDatabase("feed.xml");
$db = readDatabase("feed.xml");
print_r($db);
//printl($db[9] -> link);
//printl($db[0] -> dc_creator);
//printl($db[0] -> content_encoded);

/*
echo count($db);
$s = count($db) - 1;
for($i = 0;$i < $s;$i++)
{
	printl($db[$i] -> title);
	printl($db[$i] -> content_encoded);
	printl($db[$i] -> link);
	printl($db[$i] -> pubDate);
	printl($db[$i] -> slash_comments);
	printl("<hr>");
}
*/


?>
</body>
</html>